//
//  LDMyResumeCellEduInAll_Edit.swift
//  DingDongZP
//
//  Created by LeMac on 16/12/30.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit

class LDMyResumeCellEduInAll_Edit: LDMyResumeBaseCellInAll_Edit {
    
    
    private var editBtnTag = 3333
    lazy var voiceBtn:LDMyResumeBaseVoiceBtn = LDMyResumeBaseVoiceBtn()
    private var rowsViewTag = 2222
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupView()
    }
    
    override func updateView() {
        
        
        for item in bgView!.subviews {
            
//            if item is UIButton {
//                item.removeFromSuperview()
//            }
            item.removeFromSuperview()
        }
        for (i,_) in model!.eduexperience!.enumerate() {
            
            
            let newRowV =  LDMyResumeCellEduInAll_Row()
            newRowV.tag = rowsViewTag + i
            bgView!.addSubview(newRowV)
            
            guard let rowModel = model?.eduexperience[i] else { return }
            newRowV.model = rowModel
        }
        
        
        for (i,_) in model!.eduexperience!.enumerate() {
            
            
            let views = viewWithTag(rowsViewTag+i) as! LDMyResumeCellEduInAll_Row
            let attrH =  90
            
            let btn = getEditBtn()
            btn.tag = editBtnTag + i
            
            views.addSubview(btn)
            
            btn.snp_makeConstraints(closure: { (make) in
                
                make.top.equalTo(0)
                make.right.equalTo(-LDMargin_V*2)
                make.height.equalTo(18)
                make.width.equalTo(45)
            })
            
            
            if i < 1 {
                
                views.snp_makeConstraints(closure: { (make) in
                    
                    make.top.equalTo(bgView!.snp_top).offset(LDMargin_V*4)
                    make.left.equalTo(LDMargin_V*3)
                    make.right.equalTo(-LDMargin_V*3)
                    make.height.equalTo(attrH)
                })
                
            } else {
                
                let preView = viewWithTag(rowsViewTag+i-1) as! LDMyResumeCellEduInAll_Row
                views.snp_makeConstraints(closure: { (make) in
                    make.top.equalTo(preView.snp_bottom).offset(LDMargin_V)
                    make.left.equalTo(LDMargin_V*3)
                    make.right.equalTo(-LDMargin_V*3)
                    make.height.equalTo(attrH)
                })
            }
        }
        
        bgView?.bringSubviewToFront(editBtn!)
        
    }
    //创建单独编辑按钮
    func getEditBtn() ->UIButton {
        
        
        
        let btn = UIButton()//setDetailsBtn("编辑", picName: nil, btnBackColor: LDGolbalColor.White, titleColor: LDGolbalColor.GreenAssist)
        btn.setTitle("编辑", forState: .Normal)
        btn.setTitleColor(LDGolbalColor.GreenAssist, forState: .Normal)
        btn.layer.borderWidth = 1
        btn.layer.borderColor = LDGolbalColor.GreenAssist.CGColor
        btn.layer.cornerRadius = 9
        btn.titleLabel?.font = LDFont.Font12
        
        btn.bk_whenTapped({ [weak self] in
            
            if self?.tapClosure != nil {
                
                self?.tapClosure!(index:btn.tag - (self?.editBtnTag ?? 0))
            }
            })
        
        return btn
        
    }
    
    override func getCellHeight(model: DDMyResumeModel) -> CGFloat {
        
        let rowCount = model.eduexperience.count
        
        let allH = rowCount * 90 + 30 //+ 50
        
        return CGFloat(allH)
        
    }
    
    func setupView() {
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}
